package com.tanhua.manage.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanhua.manage.vo.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface LogMapper extends BaseMapper<Log> {
    /**
     * 统计log表中，今日的注册人数、登录人数
     * @param type
     * @param todayDate
     */
    @Select("SELECT COUNT(*) FROM tb_log WHERE TYPE=#{type} AND log_time=#{todayDate}")
    Integer queryNumByTimeAndDate(@Param("type") String type,@Param("todayDate") String todayDate);

    /**
     * 今日的活跃人数
     * @param todayDate
     */
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE  log_time=#{todayDate}")
    Integer queryNumActiveByTimeAndDate(@Param("todayDate") String todayDate);

    /**
     *
     * @param yesterdayTime
     * @param todayDate
     */
    @Select("SELECT COUNT(DISTINCT  user_id)  FROM tb_log WHERE user_id in (SELECT user_id FROM tb_log WHERE TYPE='02' AND log_time=#{yesterdayTime}) AND log_time=#{todayDate}")
    Integer queryNumRetentionByTimeAndDate( @Param("yesterdayTime")String yesterdayTime, @Param("todayDate")String todayDate);
}
